#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;

int n;
string s;


int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        cin >> n;
        cin >> s;
        

        LL res = 0;
        //数组中的值应该有三种状态，已经被删除了，不能被删除的，要被删除的
        for(int i = 1; i <= n; i ++){
            for(int j = i; j <= n; j += i){
                if(s[j - 1] == '1'){
                    break;
                }else if(s[j - 1] == '0'){
                    res += i;
                    s[j - 1] = '2';
                }
            }
        }
        cout << res << endl;


    }


    return 0;
}